<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Vue 测试实例 - 菜鸟教程(runoob.com)</title>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
    <style>
      body {
        font-size: 30px;
      }
      .btn {
        padding: 10px 20px;
        font-size: 20px;
      }
    </style>
  </head>
  <body>
    <div id="app">
       <runoob ref="runoob_01"></runoob>
      <input type="button" @click="abc" value="点击我,我能过ref找到子组件的" />
    </div>

    <script>
      // 注册
      Vue.component("runoob", {
        template: "<h1 @click='add'>{{title}}</h1>",
        data(){
          return  {
            title:'自定义组件!'
          }
        },
        methods: {
          add: function() {
            this.$parent.counter++;
          }
        }
      });

      // 创建根实例
      new Vue({
        el: "#app",
        data: {
          counter: 1
        },
        methods: {
          add: function() {
            counter++;
          },
          abc: function() {
            
            console.log(this.$refs.runoob_01);
            this.$refs.runoob_01.title="我通过ref改了你"
          }
        }
      });
    </script>
  </body>
</html>
